<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>app</title>
    <link rel="stylesheet" href="../model/element.css">
    <link rel="stylesheet" href="../model/jsFn.css">
</head>
<body>
<div class="catalog">
    <h1>目录</h1>
    <ul>
        <li>
            <p><a href="#profile">ServerAgent</a></p>
            <ul>
                <li><p><a href="#jsFn_invoke">invoke</a></p></li>
            </ul>
        </li>
        <li>
            <ul>
                <li><p><a href="#jsFn_getAgent">getAgent</a></p></li>
            </ul>
        </li>
        <li>
            <ul>
                <li><p><a href="#optional">verb</a></p></li>
            </ul>
        </li>
        <li>
            <p><a href="#profile-ClientNaive">ClientNaive</a></p>
            <ul>
                <li><p><a href="#jsFn_method">method</a></p></li>
            </ul>
        </li>
    </ul>
</div>
<div id="profile">
    <h2>对象简介:</h2>
    <p>ServerAgent 基于promise的内置联网库,完美契合本框架的动词系统,分支模式</p>
</div>
<!--对象的某一个方法-->
<div class="jsFnModel" id="jsFn_invoke">
    <h3>invoke:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>ServerAgent.invoke(url,[data]) -> promise;</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>调用一个逻辑的入口函数</p>
    </div>
    <div class="version">
        <p>稳定性;2 - 稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <ul>
            <li>
                <p>url</p>
                <p>&nbsp;string&nbsp;</p>
                <p>入口函数名字</p>
            </li>
            <li>
                <p>data</p>
                <p>&nbsp;object&nbsp;</p>
                <p>传给后台的数据,默认{}</p>
            </li>
        </ul>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>promise</p>
        <p>res(data):成功回调,data:正常请求会返回res={next:'',verb:'',args:{}},而data=res.args; <br/>
            rej(e):逻辑出错,但是请求本身成功,e:逻辑出错原因,默认会执行alert(e);</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                ServerAgent.invoke('login',{userName:'张三',password:'123456'}).then(res=>{
                    console.log('登录成功');
                })
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div class="jsFnModel" id="jsFn_getAgent">
    <h3>getAgent:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>getAgent(naive) -> {invoke:()=>{};</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>调用一个逻辑的分支函数</p>
    </div>
    <div class="version">
        <p>稳定性;2 - 稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <ul>
            <li>
                <p>naive</p>
                <p>&nbsp;string&nbsp;</p>
                <p>分支函数的naive,有ServerAgent.invoke()方法得到,此naive只能在对应的入口函数里使用</p>
            </li>
        </ul>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>{invoke:()=>{}</p>
        <p>返回的对象里只有invoke一个方法,用法和ServerAgent.invoke一样</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                ServerAgent.invoke('user',{uid:1}).then(res=>{
                    getAgent(res.naive).invoke('changeName',{name:'李四'}).then(res=>{
                        console.log('更改名字成功');
                    })
                })
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div id="attribute">
    <div id="optional">
        <h3>动词库:</h3>
        <table >
            <tbody>
            <tr>
                <th>动词名</th>
                <th>功能</th>
                <th>是否结束</th>
            </tr>
            <tr>
                <td>wsconnect</td>
                <td>socket连接</td>
                <td>否</td>
            </tr>
            <tr>
                <td>redirect</td>
                <td>页面跳传</td>
                <td>否</td>
            </tr>
            <tr>
                <td>popup</td>
                <td>弹出窗口</td>
                <td>否</td>
            </tr>
            <tr>
                <td>retrieve</td>
                <td>获得指定键值对</td>
                <td>否</td>
            </tr>
            <tr>
                <td>info</td>
                <td>前端输出提示</td>
                <td>否</td>
            </tr>
            <tr>
                <td>finish</td>
                <td>结束逻辑</td>
                <td>是</td>
            </tr>
            <tr>
                <td>store</td>
                <td>存下键值对</td>
                <td>否</td>
            </tr>
            <tr>
                <td>input</td>
                <td>打开指定页面,并返回用户的输入,然后关闭页面</td>
                <td>否</td>
            </tr>
            <tr>
                <td>hibernate</td>
                <td>冻结当前连接,在需要时用socket解冻;一般在redirect页面跳转后,逻辑没有完成,页面会一直等待网络回调,此时就需要用hibernate冻结本次网络回调</td>
                <td>否</td>
            </tr>
            <tr>
                <td>purchase</td>
                <td>苹果内购流程,只有苹果机有效</td>
                <td>否</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<div id="profile-ClientNaive">
    <h2>对象简介:</h2>
    <p>ClientNaive 基于socket.io的内置库,请定义在app.js里</p>
</div>
<div class="jsFnModel" id="jsFn_method">
    <h3>method:</h3>
    <div class="shape">
        <h3>函数使用样式</h3>
        <p>ClientNaive.method(event,fn) ->null</p>
    </div>
    <div class="profile">
        <h3>函数功能简介</h3>
        <p>监听一个socket事件,并执行对应的方法</p>
    </div>
    <div class="version">
        <p>稳定性;2 - 稳定的</p>
        <p>新增于:v0.0.0</p>
    </div>
    <div class="params">
        <h3>参数列表:</h3>
        <ul>
            <li>
                <p>event</p>
                <p>&nbsp;string&nbsp;</p>
                <p>监听的事件名称</p>
            </li>
            <li>
                <p>fn</p>
                <p>&nbsp;function&nbsp;</p>
                <p>fn(ctx,data);回调函数,ctx:没用,为了格式统一而存在;data:服务端传给前端的数据,object</p>
            </li>
        </ul>
    </div>
    <div class="res">
        <h3>返回值:</h3>
        <p>null</p>
    </div>
    <div class="code">
        <h3>例子</h3>
        <pre>
            <code>
                ClientNaive.method('chat',(ctx,data)=>{
                    let context = stack.get();
                    try {
                        //判断当前页面是否是聊天页面
                        if (context.href === "zn/message-chat.xml") {
                            console.log('刷新页面');
                        } else {
                            console.log('来电提示音');
                        }

                    } catch (e) {
                        console.log(e);
                    }
                    console.log("message end");
                    return true;
                });
            </code>
        </pre>
    </div>
    <div class="error">
        <h3>抛出错误</h3>
    </div>
</div>
<div class="author"><p>by-草草</p></div>
</body>
</html>